layui.define(function(exports){
    var $ = layui.$
        ,echarts = layui.echarts
        ,echartsTheme = layui.echartsTheme;




    AjaxGet = function(options){
        
        var url = options.url
            ,use_message = options.use_message | false
            ,success_message = options.success_message | "数据已同步到最新状态";
    
        $.ajax({
            url: url,
            type:"get",
            success:function (res) {
                // access_list->json字符串
                
                if(use_message){
                    layer.msg(success_message);
                }

                typeof options.done === 'function' && options.done(res); 
            
            }
        });

    }

    var myDate = new Date();
    DateGet = function(){
        function format_date(year, month, day, hour, minute, second){
            month += 1;
            if(month<10){
                month = '0' + month;
            }
            if(day<10){
                day = '0' + day;
            }
            if(hour==0){
                hour = '00'
            } else if(hour<10){
                hour = '0'+ hour;
            }
            if(minute == 0){
                minute = '00'
            } else if(minute<10){
                minute = '0' + minute;
            }
            if(second==0){
                second = '00';
            }else if(second<10){
                second = '0' + second;
            }

            return year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second
        }
        return {
            getToday: function(){
                var time_str = format_date(myDate.getFullYear(), myDate.getMonth(), myDate.getDate(), myDate.getHours(), myDate.getMinutes(), myDate.getSeconds());
                return time_str;
            },
            getAnHourAgo: function(){
                var before = myDate-1000*60*60;//当前日期时间戳减去一小时时间戳
                var beforeDate = new Date(before);//将时间戳转化为Date对象
                var time_str = format_date(beforeDate.getFullYear(), beforeDate.getMonth(), beforeDate.getDate(), beforeDate.getHours(), beforeDate.getMinutes(), beforeDate.getSeconds());
                return time_str;
            },
            getYesterday: function(){
                var before = myDate-1000*60*60*24;//当前日期时间戳减去一天时间戳
                var beforeDate = new Date(before);//将时间戳转化为Date对象
                var time_str = format_date(beforeDate.getFullYear(), beforeDate.getMonth(), beforeDate.getDate(), beforeDate.getHours(), beforeDate.getMinutes(), beforeDate.getSeconds());
                return time_str;
            }
        }

    }
    //外部接口
    var common = {
        AjaxGet: AjaxGet,
        DateGet: DateGet,
    };
    
    exports('common', common)
});